package
{
	import flash.display.MovieClip;

	public class OneWayPlatformObject
	{
		public var name:String;
		public var xw:Number;
		public var yw:Number;
		public var pos:Vector2;
		public var dir:Vector2;
		public var dirEnum:Number;
		public var mc:MovieClip;

		public function OneWayPlatformObject()
		{
			this.name = "oneway block";
			this.xw = Main.getInstance().tiles.xw;
			this.yw = Main.getInstance().tiles.xw;
			this.pos = new Vector2(10, 20);
			this.dir = new Vector2(0, 1);
			this.dirEnum = DroneObject.AI_DIR_U;
			Main.getInstance().objects.Register(this);
			this.mc = Main.getInstance().gfx.CreateSprite("debugOneWayPlatformMC", NinjaGraphicsSystem.LAYER_WALLS);
			this.mc.visible = false;
		}

		public function Destruct():void
		{
			Main.getInstance().gfx.DestroyMC(this.mc);
			this.mc = null;
		}

		public function Init(params):void
		{
			var _local3 = params;
			if (_local3.length = 3)
			{
				this.pos.x = _local3[0];
				this.pos.y = _local3[1];
				var _local2 = _local3[2];
				this.dirEnum = _local2;
				if (_local2 == DroneObject.AI_DIR_U)
				{
					this.dir.x = 0;
					this.dir.y = -1;
				}
				else if (_local2 == DroneObject.AI_DIR_D)
				{
					this.dir.x = 0;
					this.dir.y = 1;
					this.mc.rotation = 180;
				}
				else if (_local2 == DroneObject.AI_DIR_L)
				{
					this.dir.x = -1;
					this.dir.y = 0;
					this.mc.rotation = -90;
				}
				else if (_local2 == DroneObject.AI_DIR_R)
				{
					this.dir.x = 1;
					this.dir.y = 0;
					this.mc.rotation = 90;
				}
				this.mc.x = this.pos.x;
				this.mc.y = this.pos.y;
				this.mc.scaleX = 2 * this.xw;
				this.mc.scaleY = 2 * this.yw;
				this.mc.visible = true;
				Main.getInstance().objects.AddToGrid(this);
				Main.getInstance().objects.Moved(this);
			}
		}

		public function UnInit():void
		{
			Main.getInstance().objects.RemoveFromGrid(this);
		}

		public function DumpInitData():String
		{
			return "" + this.pos.x + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.pos.y + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.dirEnum;
		}

		public function IdleAfterDeath():void
		{
			Main.getInstance().objects.RemoveFromGrid(this);
		}

		public function TestVsPlayer(guy):void
		{
			var _local2 = guy;
			var _local3 = _local2.pos;
			var dy = (_local3.y - this.pos.y);
			var py = ((this.yw + _local2.yw) - Math.abs(dy));
			if (0 < py)
			{
				var dx = (_local3.x - this.pos.x);
				var px = ((this.xw + _local2.xw) - Math.abs(dx));
				if (0 < px)
				{
					if (this.dir.x == 0)
					{
						var v = (_local2.pos.y - _local2.oldpos.y);
						if ((v * this.dir.y) <= 0)
						{
							var testV = ((_local2.oldpos.y - (this.dir.y * _local2.yw)) - (this.pos.y + (this.dir.y * this.yw)));
							if (0 <= (testV * this.dir.y))
							{
								var vy = ((this.pos.y + (this.dir.y * this.yw)) - (_local2.pos.y - (this.dir.y * _local2.yw)));
								_local2.ReportCollisionVsObject(0, vy, 0, this.dir.y, this);
							}
						}
					}
					else
					{
						var v = (_local2.pos.x - _local2.oldpos.x);
						if ((v * this.dir.x) <= 0)
						{
							var testV = ((_local2.oldpos.x - (this.dir.x * _local2.xw)) - (this.pos.x + (this.dir.x * this.xw)));
							if (0 <= (testV * this.dir.x))
							{
								var vx = ((this.pos.x + (this.dir.x * this.xw)) - (_local2.pos.x - (this.dir.x * _local2.xw)));
								_local2.ReportCollisionVsObject(vx, 0, this.dir.x, 0, this);
							}
						}
					}
				}
			}
		}
	}
}